package com.hcy.asyncfiledownload.ordermodule.mq;

import com.hcy.asyncfiledownload.common.entry.ExportRecord;
import com.hcy.asyncfiledownload.common.event.MockMqExportEvent;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEvent;
import org.springframework.stereotype.Component;

/**
 * @Author huchenying
 * @Date 2022/9/6 15:08
 * @Description 通过spring事件模拟Mq provider
 */
@Component
@Log4j2
public class MockMqProvider implements ApplicationContextAware {

    ApplicationContext applicationContext;

    public void pushMessage(ExportRecord exportRecord){
        applicationContext.publishEvent(new MockMqExportEvent(exportRecord));
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
